using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FastPoster.DataProviders.DAO
{
	#region using
	using System.Data;
	using FastPoster.DataProviders.DTO;
    using System.Data.OleDb;
	#endregion
	public class DienDanDAO : AbstractDAO
	{
		public DienDanDAO(String strPath): base(strPath)
		{
		}

        public DataSet RetrieveMaxID()
        {
            DataSet ds;
            try
            {
                ds = new DataSet();
                base.sql = "usp_DienDan_RetrieveMaxID";
                base.FillDataSet(ref ds, "DienDan");
                return ds;
            }
            catch (System.Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
            finally
            {
                base.CleanUpObject();
            }
        }

		public DataSet SelectAll()
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_DienDan_SelectAll";
				base.FillDataSet(ref ds, "DienDan");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

		public DataSet SelectByID(int id)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_DienDan_SelectByID";
				base.InitializeCommand();
				base.AddParameter("@ID", OleDbType.Integer, 1000, id);
				base.FillDataSet(ref ds, "DienDan");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

		public bool Insert(DienDanDTO obj)
		{
			try
			{
				base.sql = "usp_DienDan_Insert";
				base.InitializeCommand();
				base.AddParameter("@URL", OleDbType.VarChar, 1000, obj.URL);
				base.AddParameter("@TenDangNhap", OleDbType.VarChar, 1000, obj.TenDangNhap);
				base.AddParameter("@MatKhau", OleDbType.VarChar, 1000, obj.MatKhau);
				return ExecuteStoredProcedure();
			}
			catch
			{
				return false;
			}
		}

		public bool Update(DienDanDTO obj)
		{
			try
			{
				base.sql = "usp_DienDan_Update";
				base.InitializeCommand();
				base.AddParameter("@URL", OleDbType.VarChar, 1000, obj.URL);
				base.AddParameter("@TenDangNhap", OleDbType.VarChar, 1000, obj.TenDangNhap);
				base.AddParameter("@MatKhau", OleDbType.VarChar, 1000, obj.MatKhau);
                base.AddParameter("@ID", OleDbType.Integer, 1000, obj.ID);
				return ExecuteStoredProcedure();
			}
			catch
			{
				return false;
			}
		}

		public bool Delete(int id)
		{
			try
			{
				base.sql = "usp_DienDan_Delete";
				base.InitializeCommand();
				base.AddParameter("@ID", OleDbType.Integer, 1000, id);
				return ExecuteStoredProcedure();
			}
			catch
			{
				return false;
			}
		}

	}
}